package com.coolpad.job.device.model;

/**
 * 功能描述:响应构建<br/>
 *
 * @Author:shengtao_yang
 * @Date: 2020/12/21 13:26
 * @since: 1.0.0
 */
public enum Response {

    success(){
        @Override
        public ResponseDTO build() {
            return buildResponse(ResponseConstants.success_code,ResponseConstants.success_msg);
        }
    },
    failure(){
        @Override
        public ResponseDTO build() {
            return buildResponse(ResponseConstants.fail_code,ResponseConstants.fail_msg);
        }
    },
    exception(){
        @Override
        public ResponseDTO build() {
            return buildResponse(ResponseConstants.fail_code,ResponseConstants.exc_msg);
        }
    };


    private static ResponseDTO buildResponse(int code, String msg){
        return ResponseDTO.builder().code(code).msg(msg).build();
    }

    public abstract ResponseDTO build();

    /**
     * response constants
     */
    private static class ResponseConstants {

        private static final int success_code = 200;
        private static final String success_msg = "成功";

        private static final int fail_code = 400;
        private static final String fail_msg = "失败";

        private static final String exc_msg = "异常";
    }
}
